/*
 * JOY电子商务网运营事业部
 * 中国移动通信集团设计院有限公司
 * B2BJOY.COM  OPERATION  DIVISION
 * China Mobile Group Design Institute Co., Ltd
 */

package com.uhaou.system.dao.impl;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.uhaou.common.base.BaseIbatisDao;
import com.uhaou.common.base.IdGenerator;
import com.uhaou.system.dao.ISysDictDao;
import com.uhaou.system.model.SysDict;
import com.uhaou.system.vo.query.SysDictQuery;

/**
 * @author  jiangcheng
 * @version 1.0
 * @since 1.0
 */




@Repository("sysDictDao")
public class SysDictDaoImpl extends BaseIbatisDao<SysDict,java.lang.String> implements ISysDictDao{
	
	@Override
	public String getIbatisSqlMapNamespace() {
		return "sysDict";
	}
	
	public SysDict getById(java.lang.String id){
		return super.getById( id);
	}
	
	public void deleteById(java.lang.String id){
		super.deleteById(id);
	}
	
	/**
	 * 删除子信息
	 * @param dCode
	 */
	public void deleteSubByCode(String dCode){
		getSqlMapClientTemplate().delete("SysDict.deleteSub", dCode);
	}
	
	/** 插入数据 */
	public void save(SysDict entity){
		if(StringUtils.isEmpty(entity.getId())) {
			entity.setId(IdGenerator.genUUIDStr());
		}
		super.save(entity);
	}
	
	/** 更新数据 */
	public void update(SysDict entity){
		super.update(entity);
	}

	public boolean isUnique(SysDict entity, String uniquePropertyNames){
		return super.isUnique( entity, uniquePropertyNames);
	}
	 
	
	public List<SysDict> find(SysDictQuery query) {
		return getSqlMapClientTemplate().queryForList("SysDict.find", query);
	}

	public void saveOrUpdate(SysDict entity) throws DataAccessException {
		if(StringUtils.isEmpty(entity.getId())) {
			entity.setId(IdGenerator.genUUIDStr());
			super.save(entity);
		}
		else 
			super.update(entity);
		
	}
	
	/**
	 * 获取最大的编码
	 * @param supCode
	 * @return
	 */
	public String getMaxCode(String supCode){
		return (String) getSqlMapClientTemplate().queryForObject("SysDict.getMaxCode",supCode);
	}
	
	/**
	 * 获取字典键值对
	 * @param supCode
	 * @return
	 */
	public List<SysDict> getDictNameValue(String supCode) {
		return getSqlMapClientTemplate().queryForList("SysDict.findNameValue", supCode);
	}

	public List<SysDict> findExpValueListByCode(String dictCode){
		return (List<SysDict>)this.getSqlMapClientTemplate().queryForList("SysDict.expValueList", dictCode);
	}
	public List<SysDict> findAll(){
		return getSqlMapClientTemplate().queryForList("SysDict.findAll");
	}

}
